package com.example.poemtest.Activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.poemtest.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

/**
 * created by JHT on 2024/1/19
 */
public class BottomNavigationViewActivity extends AppCompatActivity {
    private FragmentManager fragmentManager;
    private String flag;

    @Override
    public FragmentManager getSupportFragmentManager() {
        fragmentManager = super.getSupportFragmentManager();
        return fragmentManager;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACTIVITY_RECOGNITION}, 1);
        }

//        FullScreenUtil.getInstance().fullScreen(this,true);
        setContentView(R.layout.activity_bottom_navigation_view);

        //实例化BottomNavigationView
        BottomNavigationView navView = findViewById(R.id.nav_view);
        navView.setItemIconTintList(null);
//        // 配置navigation与底部菜单之间的联系
//        // 底部菜单的样式里面的item里面的ID与navigation布局里面指定的ID必须相同，否则会出现绑定失败的情况
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_index, R.id.navigation_category,R.id.navigation_find,R.id.navigation_mine)
                .build();
//
        // 建立fragment容器的控制器，这个容器就是页面的上的fragment容器
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        // 启动
        //NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView,navController);

        //这里是从设置页面跳转回我的页面，但是没跳转成功，这个代码好像没起作用
        Integer id = getIntent().getIntExtra("id", 1);
        switch (id) {
            case 1:
                navView.setSelectedItemId(R.id.navigation_index);
                break;
            case 2:
                navView.setSelectedItemId(R.id.navigation_category);
                break;
            case 3:
                navView.setSelectedItemId(R.id.navigation_find);
                break;
            case 4:
                navView.setSelectedItemId(R.id.navigation_mine);
                break;
            default:
                break;
        }

    }

    //设置跳转时无动画
    @Override
    protected void onPause() {
        overridePendingTransition(0,0);
        super.onPause();
    }
}
